<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sales__sales}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-select v-model="dataForm.houseId" placeholder="猪舍" clearable>
            <el-option
                v-for="item in houses"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.earmark" placeholder="耳号" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.salesType" placeholder="销售类型" clearable>
            <el-option label="正常销售" value="正常销售"></el-option>
            <el-option label="淘汰销售" value="淘汰销售"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.type" placeholder="类型" clearable>
            <el-option label="种猪" value="种猪"></el-option>
            <el-option label="生长猪" value="生长猪"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
              v-model="dataForm.salesDate"
              align="right"
              type="date"
              placeholder="销售日期"
              :picker-options="pickerOptions"
              value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.operatorName" placeholder="操作人" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
<!--        <el-form-item>-->
<!--          <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button v-if="$hasPermission('sales:sales:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('sales:sales:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
<!--        <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
<!--        <el-table-column prop="houseId" label="所在猪舍" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="houseName" label="猪舍" header-align="center" align="center"></el-table-column>
        <el-table-column prop="type" label="类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="salesDate" label="销售日期" header-align="center" align="center"></el-table-column>
        <el-table-column prop="grid" label="栏位" header-align="center" align="center"></el-table-column>
        <el-table-column prop="price" label="总价" header-align="center" align="center"></el-table-column>
        <el-table-column prop="unitFee" label="单价" header-align="center" align="center"></el-table-column>
        <el-table-column prop="unit" label="单位" header-align="center" align="center"></el-table-column>
        <el-table-column prop="earmark" label="耳号" header-align="center" align="center"></el-table-column>
        <el-table-column prop="weight" label="重量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="remark" label="备注" header-align="center" align="center"></el-table-column>
        <el-table-column prop="mounts" label="数量" header-align="center" align="center"></el-table-column>
        <el-table-column prop="reason" label="淘汰原因" header-align="center" align="center"></el-table-column>
        <el-table-column prop="operatorName" label="操作人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="salesType" label="销售类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="updateDate" label="更新时间" header-align="center" align="center"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('sales:sales:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('sales:sales:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
/* eslint-disable */
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './sales-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sales/sales/page',
        getDataListIsPage: true,
        exportURL: '/sales/sales/export',
        deleteURL: '/sales/sales',
        deleteIsBatch: true
      },
      dataForm: {
        id: ''
      }
    }
  },
  components: {
    AddOrUpdate
  },
  created() {
    this.getHouses()
  },
  methods: {
    getHouses () {
      let that = this;
      this.$http.get(`/basic/house/all`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.houses = res.data
      }).catch(() => {})
    },
  }
}
</script>
